package tests;

import constants.Colors;
import constants.Difficulties;
import constants.Races;
import data.Map;
import data.Player;
import data.Shopping;
import data.Store;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.*;

/**
 * tests
 *
 * @author Jared Moore
 * @date 11/5/13
 */
public class MapTest {

	private Map map;

	@Before
	public void setUp() throws Exception {
		map = new Map(Difficulties.BEGINNER, false, 2);
	}

	@Test
	public void testRemoveM() throws Exception {
		String six = "YOUR SPACE GYPSY IN-LAWS MADE A MESS OF THE TOWN. IT COST YOU $12 TO CLEAN IT UP.";
		assertEquals(six, map.removeM(6, 2));

		String four = "FLYING CAT-BUGS ATE THE ROOF OFF YOUR HOUSE. REPAIRS COST $8.";
		assertEquals(four, map.removeM(4, 2));

		String three = "YOU FOUND A DEAD MOOSE RAT AND SOLD THE HIDE FOR $4.";
		assertEquals(three, map.removeM(3, 2));

		String two = "THE MUSEUM BOUGHT YOUR ANTIQUE PERSONAL COMPUTER FOR $16.";
		assertEquals(two, map.removeM(2, 2));

	}

	@Test
	public void testNextTurn() throws Exception {
		map.buildPlayer("1", Races.HUMAN, Colors.BLUE);
		map.buildPlayer("2", Races.HUMAN, Colors.GREEN);

		Player player = map.getCurrentPlayer();
		map.nextTurn();

		assertThat(player, not(map.getCurrentPlayer()));          //asserts that the turn as moved to another Player
		assertThat("1", is(map.getCurrentPlayer().getName()));    //asserts that the turn has moved to the correct player

		map.gamble(50);

		assertEquals("1", map.getCurrentPlayer().getName());      //asserts that after the round ended, the player with the most money goes first


	}

	@Test
	public void testShopping() throws Exception {
		int[] resources = new int[3];
		Player player = new Player("Brett", Races.HUMAN, Colors.BLUE, resources);
		Store store = new Store(Difficulties.BEGINNER);
		//Food - Player has 600 money; food cost 40
		assertFalse(Shopping.playerBuysFood(player, store, 500));
		assertTrue(Shopping.playerBuysFood(player, store, 1));
		assertEquals(player.getMoney(), 560);

		//Energy - Player has 560 money; energy cost 100
		assertFalse(Shopping.playerBuysEnergy(player, store, 500));
		assertTrue(Shopping.playerBuysEnergy(player, store, 1));
		assertEquals(player.getMoney(), 460);

		//Ore - Player has 460 money; food cost 70
		assertFalse(Shopping.playerBuysOre(player, store, 500));
		assertTrue(Shopping.playerBuysOre(player, store, 1));
		assertEquals(player.getMoney(), 360);
	}
}
